'''
import keyword
print(keyword.kwlist)

print(random.randint(1, 10))  # 1, 2, 3, 4, 5, 6, 7, 8, 9, 10

range(1,6) # 1, 2, 3, 4, 5
range(6)   # 0, 1, 2, 3, 4, 5
print(r"hello\nworld")  # \n因为r而失效(爬取数据常用)
爬虫常用：lstrip、rstrip
join(str,",")组合
split(str,",")拆开
print("你好" * 3)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 列表
list = [11,2,3]
增
list.append(22)     结果：[11,2,3,22]
list.append([3,4])  结果：[11,2,3,[3,4])
list.extend([1,2])  结果：[11,2,3,1,2]
list.insert(1,88)   结果：[11,88,2,3]
删
del list[0] 删除11（指定位置）
list.pop()  删除3
list.pop(0) 删除11
list.remove(11) 删除11（指定内容）
清空：
list.clear()      结果：list = []
改
list[0] = 9   结果：[11,2,9]
查
a = input("请输入：")
if a in list:
   print("在里面")
else
   print("不在")
list.index(11) 结果：0（11的下标为0）
list.index(11,0,2) 结果：0 在[0,2)区间，11的下标为0
list.index(11,1,2) 结果：报错 [1,2)区间，没有11
list.count(11) 结果：1（11的个数）
list.sort() 升序
list.sort(reverse=True) 降序
list.reverse() 反转
list[::-1] 反转
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 元组
tuple = (50)  int类型
tuple = (50,) 元组类型
tuple = ()    元组类型
增：
tuple = tuple1 + tuple2
删：
del tuple1 (删除整个tuple1，打印会报错，显示找不到tuple)
清空：
tuple.clear()      结果：tuple = ()
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 字典
dic = {"name":"zhangsan","age":19}
print(dic["name"]) 结果：'zhangsan'
print(dic["gender"]) 结果：报错，找不到gender
print(dic.get("gender","男")) 结果：找不到gender，默认返回'男'
增：
dic["addr"] = "北京" 结果：dic = {"name":"zhangsan","age":19,"addr","北京"}
删：
del dic["name"]  结果：dic = {"age":19}
del dic (删除整个dic，打印会报错，显示找不到dic)
清空：
dic.clear()      结果：dic = {}
改：
# python 指定非0和非空值为Ture,0或None为False
查：
dic.keys()  结果：dic_keys(['name','age','addr'])
dic.values() 结果：dic_values(['zhangsan',19,'北京'])
dic.items()  结果：dic_items([('name','zhangsan'),('age',19),('addr','北京')])  每个键值对是一个元组
遍历所有的值：
for key,value in dic.items():
    print(f"key = {key},value = {value}")

使用枚举函数，同时拿到列表中的下标和元素内容
list = ['a','b','c','d']
for i,x in enumerate(list):
print(i,x)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 集合
set = {1,2,3,2,2,3,5}  结果：set = {1,2,3,5},自动去重（可理解为没有key的字典类型）

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 函数
def div(a,b):
  shang = a//b
  yushu = a%b
  return shang,yushu
shang,yu = div(11,2)
print(f"shang:{shang},yushu:{yushu}")
 ----
 a= 100
 def f1():
    global a
    print(f"修改前的：{a}")   结果：100
    a =200
    print(f"修改后的：{a}")  结果：200
def f2():
   print(a)  结果：200

---'''
# f = open("test.txt","r")
# # f.write("hello")
# print(f.read(3))
# f.close()
'''
----
try:
   print(num)
   f = open("11.txt","r")
   print("__")
except (IOError,NameError) as result:
   pass
   或
   print(f"发生错误了：{result}")
   
try:
   f = open("123.txt","r")
   try:
      while True:
         content = f.readline()
         if content == 0:
            break
         time.sleep(2)
         print(content)
      finally:
        f.close()
        print("文件关闭")
except Exception as result:
   print(f"出现异常了：{result}")
========================================================================
if 0:
    print(111)
else:
    print(222)


score = int(input("请输入分数："))
if score <= 100 and score >= 90:
    print("优秀")
elif score >= 80:
    print("良好")
elif score >= 70:
    print("一般")
elif score >= 60:
    print("及格")
else:
    print("不合格")
print("再接再厉")

import random

0：剪刀
1：石头
2：布

import random
a = int(input("请输入："))
b = random.randint(0,2)
flag = 1
print(f"随机生成的数是：{b}")
while flag:
    if a == b:
        a = int(input("请重新输入："))
        continue
    elif a > b:
     print("哟呵，你赢了！")
     break
    else:
        print("哈哈，你输了！")
        break
    print("下次再来")


for i in range(5):   # [0, 1, 2, 3, 4]
    print(i, end='\n')

sum = 0
i = 1
while i <= 100:
    sum += i
    i += 1
print(sum)

用 for 和 while 写九九乘法表
for i in range(1, 10):
    for j in range(1, i+1):
        print(f"{j} * {i} = {j * i}", end='\t')
    i += 1
    print()

i = 1
while i <= 9:
    j = 1
    while j <= i:
        print(f"{j} * {i} = {j * i}", end="\t")
        j += 1
    i += 1
    print()



a = "chengdu"
print(a[-1])

i = 1
list = [1,2,3,4,"zhangsan"]
while i <= len(list):
    print(list[i-1])
    i += 1


list = [11,2,3,4]
# list.pop()
# del list[0]
# list.remove(11)
a = list.index(11)
print(a)

import random
teacher = ["小张", "小王", "小李", "小刘", "小周", "小贾", "小白", "小孙", "小邓", "小郑"]
offices = [[], [], []]
i = 1
for name in teacher:
    index = random.randint(0, 2)
    offices[index].append(name)
print(offices)
i = 1
for office in offices:
    print(f"第{i}个办公室的人数：{len(office)}")
    i += 1
    for name in office:
        print(f"{name}",end = "\t")
    print()
    print("-"*20)

'''
#
# print(('-' * 4) + " 商品列表 " + ('-' * 4))
# products = [["iphone", 6888], ["MacPro", 14800], ["小米6", 2499], ["Coffee", 31], ["Book", 60], ["Nike", 699]]
#
# num = int(input("请输入商品编号："))
# while True:
#     if num < len(products):
#         print(f"{num  } {products[num][0]  } \t{products[num][1]}")
#         num = int(input("请重新输入商品编号："))
#         continue
#     else:
#         break
#



# num = int(input("请输入商品编号："))
# if num

# dic = {"name":"zhangsan","age":19}
# del dic["name"]
# print(dic)
#
#
#
#
# list = ['a','b','c','d']
# for i,x in enumerate(list):
#     print(i,x)

#
# def div(a,b):
#   shang = a//b
#   yushu = a%b
#   return shang,yushu
# shang,yushu = div(11,2)
# print(f"shang:{shang},yushu:{yushu}")

#
# def sum():
#     print("-"*30)
#
#
# def avg(num):
#     i = 1
#     while i <= num:
#         sum()
#         i += 1
#
# avg(int(input("请输入：")))
#
#


# def w():
#     try:
#         with open('test.txt', 'w') as f:
#             f.write('hello, world')
#     except Exception as ex:
#         print(ex)
#
#
# def r():
#     with open('test.txt', 'r') as f:
#         result = f.read()
#
#     with open('copy.txt', 'w') as f:
#         f.write(result)
#     print('操作完毕')



#
# try:
#     w()
#     r()
# except Exception as ex:
#     print('catch error:', ex)



def w():
    f = open("gushi.txt", "w")
    f.write("鹅鹅鹅，\n曲项向天歌，\n白毛浮绿水，\n红掌拨清波")

def r():
    f1 = open("gushi.txt", "r")
    content = f1.read()
    f2 = open("copy.txt", "w")
    f2.write(content)
    print("复制完毕")
    f1.close()
    f2.close()
try:
    w()
    r()
except Exception as result:
    print(f"出错了：{result}")